<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>优惠券批次范围更新</title>
<link href="../img/base.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="/img/jquery.js"></script>
<script language="javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	function checkCouponBatch(){
		var tof = true;
		
		var code_id = $('#code').val();
		
		if(code_id == 'cinemaid' || code_id == 'film_id'){
			$("#code_value option").attr('selected','selected');	
		}
		
		if(code_id == 'show_date'){
			var start_date = $('#start_date').val();
			var end_date = $('#end_date').val();
			if(start_date.length < 1 || end_date < 1){
				tof = false;
				alert('日期范围的开始与结束值都不能为空');	
			}
		}else if(code_id == 'total_amount'){
			var start_price = $('#start_price').val();
			var end_price = $('#end_price').val();
			var str = /^\d+$/;
			if(start_price.length < 1 || end_price < 1){
				tof = false;
				alert('总价范围的开始与结束值都不能为空');	
			}else if(!str.test(start_price) || !str.test(end_price)){
				tof = false;
				alert('总价范围的开始与结束值都必须是数字');	
			}
		}else if(code_id == 'show_time'){
			var start_time= $('#start_time').val();
			var end_time = $('#end_time').val();
			if(start_time.length < 1 || end_time < 1){
				tof = false;
				alert('时间范围的开始与结束值都不能为空');	
			}
		}
		else{
			var code_value = $('#code_value').val();
			if(code_value.length < 1 && code_id != 'all'){
				tof = false;
				alert('范围值不能为空');	
			}
		}
		
		return tof;
	}
	
	function changeValue(){
		var code_id = $('#code').val();
		var str = '';
		
		if(code_id == 'cinemaid')
		{
			$.getJSON('coupon_scope.php',{op:'cinema',batch_id:<{$batch_id}>},
				function(data){
					str += '<div style="float:left"><select id="source" name="source" multiple="multiple" size="10">';
					$.each(data,function(i,v){
						str += '<option value="'+v.cinemaid+'">'+v.cinema_name+'</option>';				
					});
					str += '</select></div>';	
					
					str += '<div style="float:left;width:30px;margin:0 10px;"><ul>';
					str += '<li><input type="button" class="coolbg np" value=">&nbsp;" onclick="rightValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value=">>" onclick="rightAllValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value="<&nbsp;" onclick="leftValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value="<<" onclick="leftAllValue()" /></li>';
					str += '</ul></div>';
					
					str += '<div style="float:left"><select id="code_value" name="code_value[]" multiple="multiple" size="10">';
					str += '</select></div>';
					
					$('#code_info').html(str);
				}
			);
		}else if(code_id == 'film_id'){
			$.getJSON('coupon_scope.php',{op:'film',batch_id:<{$batch_id}>},
				function(data){
					str += '<div style="float:left"><select id="source" name="source" multiple="multiple" size="10">';
					$.each(data,function(i,v){
						str += '<option value="'+v.film_id+'">'+v.film_id+' '+v.film_name+'</option>';				
					});
					str += '</select></div>';	
					
					str += '<div style="float:left;width:30px;margin:0 10px;"><ul>';
					str += '<li><input type="button" class="coolbg np" value=">&nbsp;" onclick="rightValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value=">>" onclick="rightAllValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value="<&nbsp;" onclick="leftValue()" /></li>';
					str += '<li><input type="button" class="coolbg np" value="<<" onclick="leftAllValue()" /></li>';
					str += '</ul></div>';
					
					str += '<div style="float:left"><select id="code_value" name="code_value[]" multiple="multiple" size="10">';
					str += '</select></div>';
					
					$('#code_info').html(str);
				}
			);
		}else if(code_id == 'seq_no'){
			str += '<textarea id="code_value" name="code_value" rows="3" cols="80"></textarea><span style="color:#F00">* 多个场次编号请用“##”隔开</span>';
			$('#code_info').html(str);
		}else if(code_id == 'show_date'){
			str += '<input type="text" name="start_date" id="start_date" onClick="WdatePicker()"  /> - <input type="text" name="end_date" id="end_date" onClick="WdatePicker()"  />';
			$('#code_info').html(str);
		}else if(code_id == 'dimensional'){
			str += '<select name="code_value">';
			str += '<option value="2D">2D</option>';
			str += '<option value="3D">3D</option>';
			str += '</select>';
			$('#code_info').html(str);
		}else if(code_id == 'hall_name'){
			str += '<input type="text" name="code_value" id="code_value"  />';	
			$('#code_info').html(str);
		}else if(code_id == 'total_amount'){
			str += '<input type="text" name="start_price" id="start_price"  /> - <input type="text" name="end_price" id="end_price" />';
			$('#code_info').html(str);
		}else if(code_id == 'show_time'){
			str +='<input  type="text" name="start_time" id="start_time" onClick="WdatePicker({dateFmt:\'HH:mm:ss\'})"  /> - <input type="text" name="end_time" id="end_time" onClick="WdatePicker({dateFmt:\'HH:mm:ss\'})"  />';
			$('#code_info').html(str);
		}
	}
	
	function rightValue(){
		$("#source option:selected").appendTo($("#code_value"));
	}
	
	function rightAllValue(){
		$("#source option").appendTo($("#code_value"));	
	}
	
	function leftValue(){
		$("#code_value option:selected").appendTo($("#source"));	
	}
	
	function leftAllValue(){
		$("#code_value option").appendTo($("#source"));	
	}
</script>
</head>
<body leftmargin='15' topmargin='10' bgcolor="#FFFFFF">
<table width="97%" border="0" align="center" cellpadding="0" cellspacing="0" id="head1" style="border-bottom:1px solid #CCCCCC">
	<tr>
    	<td align='center' valign='top' colspan="2">
            <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D1DDAA">
                <tr>
                    <td height="26" background="../img/newlinebg3.gif">
                        <table width="98%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="right">
                                    <input type='button' class="coolbg np" onClick="location='coupon_scope.php?batch_id=<{$batch_id}>';" value='返回' />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
    	<td>
        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr bgcolor="#FFFFFF">
                    <td height="4"></td>
                </tr>
            </table>
        </td>
    </tr>
  	<tr>
    	<td colspan="2">
      		<table width="800" border="0" cellpadding="0" cellspacing="0">
        		<tr>
          			<td width="84" height="24" align="center" background="../img/itemnote1.gif">&nbsp;<{if $op == 'update'}>修改<{else}>添加<{/if}>批次范围&nbsp;</td>
          			<td width="84"></td>
          			<td>&nbsp;</td>
        		</tr>
      		</table>
    	</td>
	</tr>
</table>
<form name="form1" action="" enctype="multipart/form-data" method="post" onsubmit="return checkCouponBatch()">
<table width="98%"  border="0" align="center" cellpadding="2" cellspacing="2" id="needset">
  	<tr>
    	<td height="24" colspan="4" class="bline">
      		<table width="800" border="0" cellspacing="0" cellpadding="0">
        		<tr>
                    <td width="90">&nbsp;类型：</td>
          			<td width="35%">
                    	<select name="type" <{if $op == 'update'}>disabled="disabled"<{/if}>>
                            <option value="white" <{if $scope_info.scope_type == 'white'}>selected="selected"<{/if}>>白名单</option>
                            <option value="black" <{if $scope_info.scope_type == 'black'}>selected="selected"<{/if}>>黑名单</option>
                        </select>
                    </td>
                    <td width="90">&nbsp;范围：</td>
          			<td width="35%">
                    	<select id="code" name="code" onchange="changeValue()" <{if $op == 'update'}>disabled="disabled"<{/if}>>
                        <{foreach from=$code_list item=code}>
                        	<option value="<{$code.code_id}>" <{if $scope_info.scope_code == $code.code_id}>selected="selected"<{/if}>><{$code.code_name}></option>
                        <{/foreach}>
                        </select>
                    </td>
        		</tr>
      		</table>      
    	</td>
  	</tr>
    <tr>
    	<td height="24" colspan="4" class="bline">
      		<table width="800" border="0" cellspacing="0" cellpadding="0">
                <tr>
          			<td width="90">&nbsp;范围值：</td>
          			<td width="85%" colspan="3" id="code_info">
                    	<{if $scope_info.scope_code == 'cinemaid'}>
                        <div style="float:left">
                        	<select id="source" name="source" multiple="multiple" size="10">
                            	<{foreach from=$cinema_not_selected item=cinema_not}>
                            	<option value="<{$cinema_not.cinemaid}>"><{$cinema_not.cinema_name}></option>
                                <{/foreach}>
                            </select>
                        </div>
                        <div style="float:left;width:30px;margin:0 10px;">
                        	<ul>
                            	<li><input type="button" class="coolbg np" value=">&nbsp;" onclick="rightValue()" /></li>
								<li><input type="button" class="coolbg np" value=">>" onclick="rightAllValue()" /></li>
								<li><input type="button" class="coolbg np" value="<&nbsp;" onclick="leftValue()" /></li>
								<li><input type="button" class="coolbg np" value="<<" onclick="leftAllValue()" /></li>
                        	</ul>
                        </div>
                        <div style="float:left">
                            <select id="code_value" name="code_value[]" multiple="multiple" size="10">
                            	<{foreach from=$cinema_selected item=cinema}>
                            	<option value="<{$cinema.cinemaid}>" selected="selected"><{$cinema.cinema_name}></option>
                                <{/foreach}>
                            </select>
                        </div>
                        <{elseif $scope_info.scope_code == 'film_id'}>
                        <div style="float:left">
                        	<select id="source" name="source" multiple="multiple" size="10">
                            	<{foreach from=$film_not_selected item=film_not}>
                            	<option value="<{$film_not.film_id}>"><{$film_not.film_id}> <{$film_not.film_name}></option>
                                <{/foreach}>
                            </select>
                        </div>
                        <div style="float:left;width:30px;margin:0 10px;">
                        	<ul>
                            	<li><input type="button" class="coolbg np" value=">&nbsp;" onclick="rightValue()" /></li>
								<li><input type="button" class="coolbg np" value=">>" onclick="rightAllValue()" /></li>
								<li><input type="button" class="coolbg np" value="<&nbsp;" onclick="leftValue()" /></li>
								<li><input type="button" class="coolbg np" value="<<" onclick="leftAllValue()" /></li>
                        	</ul>
                        </div>
                        <div style="float:left">
                            <select id="code_value" name="code_value[]" multiple="multiple" size="10">
                            	<{foreach from=$film_selected item=film}>
                            	<option value="<{$film.film_id}>" selected="selected"><{$film.film_id}> <{$film.film_name}></option>
                                <{/foreach}>
                            </select>
                        </div>
                        <{elseif $scope_info.scope_code == 'show_date'}>
                        <input type="text" name="start_date" id="start_date" value="<{$start_date}>" onClick="WdatePicker()"  /> - 
                        <input type="text" name="end_date" id="end_date" value="<{$end_date}>" onClick="WdatePicker()"  />	
                        <{elseif $scope_info.scope_code == 'total_amount'}>
                        <input type="text" name="start_price" id="start_price" value="<{$start_price}>" /> - 
                        <input type="text" name="end_price" id="end_price" value="<{$end_price}>" />
                        <{elseif $scope_info.scope_code == 'seq_no'}>
                        <textarea id="code_value" name="code_value" rows="3" cols="80"><{$code_value}></textarea><span style="color:#F00">* 多个场次编号请用“##”隔开</span>
                        <{elseif $scope_info.scope_code == 'dimensional'}>
                        <select name="code_value">
                            <option value="2D" <{if $code_value == '2D'}>selected="selected"<{/if}>>2D</option>
                            <option value="3D" <{if $code_value == '3D'}>selected="selected"<{/if}>>3D</option>
                        </select>
                        <{elseif $scope_info.scope_code == 'hall_name'}>
                        <input type="text" name="code_value" id="code_value" value="<{$code_value}>"  />
                        <{elseif $scope_info.scope_code == 'show_time'}>
                        <input  type="text" name="start_time" id="start_time" value="<{$start_time}>" onClick="WdatePicker({dateFmt:\'HH:mm:ss\'})"  /> - 
                        <input type="text" name="end_time" id="end_time" value="<{$end_time}>" onClick="WdatePicker({dateFmt:\'HH:mm:ss\'})"  />
                        <{/if}>
                    </td>
        		</tr> 
      		</table>      
    	</td>
  	</tr>
</table>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
    	<td height="56">
			<table width="98%" border="0" cellspacing="1" cellpadding="1">
        		<tr>
          			<td align="center">
          				<table width="214" border="0" cellspacing="0" cellpadding="0" >
              				<tr>
				                <td width="115">
                                	<input type="hidden" name="op" value="save" /><input type="hidden" name="batch_id" value="<{$batch_id}>" />
                                    <input type="hidden" name="action" value="<{$op}>" />
				                    <input name="imageField" type="image" src="../img/button_ok.gif" width="60" height="22" class="np" border="0"  style="cursor:pointer; ">
				                </td>
				                <td width="99">
				                	<img src="../img/button_reset.gif" width="60" height="22" border="0" onClick="location.reload();" style="cursor:pointer; ">
				                </td>
			              	</tr>
						</table>
					</td>
    			</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</body>

</html>